package com.by.controlelr;

import com.by.Service.MinioService;
import com.by.controller.BaseController;
import com.by.entity.Minio;
import com.by.entity.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


/**
 * @author 江俊俊
 * @version 1.0
 * @description
 * @date 2025/4/11 11:28
 * @since JDK1.8
 */
@Api(tags = "文件上传")
@RestController
@RequestMapping("/minio")
public class MinioController extends BaseController {

    @Autowired
    MinioService minioService;

    @Autowired
    Minio minio;

    @ApiOperation("文件上传")
    @PostMapping("/upload")
    public ResultBean upload(MultipartFile file) {
        String url = minioService.upload(file);
        return success("文件上传成功", url);
    }

    @ApiOperation("文件下载")
    @GetMapping("/download")
    public ResponseEntity<InputStreamResource> download(String url) throws Exception {
        ResponseEntity<InputStreamResource> download = minioService.download(url);
        return download;
    }

    @ApiOperation("文件删除")
    @DeleteMapping("/delete")
    public ResultBean delete(String url) {
        int delete = minioService.delete(url);
        return success("文件删除成功", deleteResult(delete));
    }
}
